package com.immortal.core.module.jpa;

import com.querydsl.jpa.impl.JPAQueryFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.io.Serializable;
import java.util.List;
import java.util.Optional;

public abstract class BaseServiceImpl<T,ID extends Serializable,R extends BaseRepository<T,ID>> implements BaseService<T,ID,R>{
    @Autowired
    protected R baseRepository;
    @Autowired
    @PersistenceContext
    private EntityManager entityManager;
    @Autowired
    JPAQueryFactory queryFactory;
    @Override
    public JPAQueryFactory getQueryFactory() {
        return  queryFactory;
    }
    @Override
    public R getRepository() {
        return baseRepository;
    }

    @Override
    public List<T> findAll() {
        return baseRepository.findAll();
    }

    @Override
    public List<T> findAll(Sort var1) {
        return baseRepository.findAll(var1);
    }

    @Override
    public List<T> findAllById(Iterable<ID> var1) {
        return baseRepository.findAllById(var1);
    }

    @Override
    public <S extends T> List<S> saveAll(Iterable<S> var1) {
        return baseRepository.saveAll(var1);
    }

    @Override
    public void flush() {
        baseRepository.flush();
    }

    @Override
    public <S extends T> S saveAndFlush(S var1) {
        return baseRepository.saveAndFlush(var1);
    }

    @Override
    public void deleteInBatch(Iterable<T> var1) {
        baseRepository.deleteInBatch(var1);
    }

    @Override
    public void deleteAllInBatch() {
        baseRepository.deleteAllInBatch();
    }

    @Override
    public T getOne(ID var1) {
        return baseRepository.getOne(var1);
    }

    @Override
    public Page<T> findAll(Pageable var1) {
        return baseRepository.findAll(var1);
    }

    @Override
    public <S extends T> Optional<S> findOne(Example<S> var1) {
        return baseRepository.findOne(var1);
    }

    @Override
    public <S extends T> Iterable<S> findAll(Example<S> var1) {
        return baseRepository.findAll(var1);
    }

    @Override
    public <S extends T> Iterable<S> findAll(Example<S> var1, Sort var2) {
        return baseRepository.findAll(var1,var2);
    }

    @Override
    public <S extends T> Page<S> findAll(Example<S> var1, Pageable var2) {
        return baseRepository.findAll(var1,var2);
    }

    @Override
    public <S extends T> long count(Example<S> var1) {
        return  baseRepository.count(var1);
    }

    @Override
    public <S extends T> boolean exists(Example<S> var1) {
        return  baseRepository.exists(var1);
    }

    @Override
    public Optional<T> findOne(Specification<T> var1) {
        return baseRepository.findOne(var1);
    }

    @Override
    public Optional<T> findById(ID var1) {
        return baseRepository.findById(var1);
    }

    @Override
    public List<T> findAll(Specification<T> var1) {
        return baseRepository.findAll(var1);
    }

    @Override
    public Page<T> findAll(Specification<T> var1, Pageable var2) {
        return baseRepository.findAll(var1,var2);
    }

    @Override
    public List<T> findAll(Specification<T> var1, Sort var2) {
        return baseRepository.findAll(var1,var2);
    }

    @Override
    public long count(Specification<T> var1) {
        return baseRepository.count(var1);
    }

    @Override
    public void deleteById(ID var1) {
       baseRepository.deleteById(var1);
    }

    @Override
    public void delete(T var1) {
        baseRepository.delete(var1);
    }

    @Override
    public void deleteAll(Iterable<? extends T> var1) {
        baseRepository.deleteAll(var1);
    }

    @Override
    public void deleteAll() {
        baseRepository.deleteAll();
    }

    @Override
    public T save(T var1) {
        return baseRepository.save(var1);
    }
}
